package com.manager.commons;


import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MD5
{

    public MD5()
    {
    }

    public static String MD5Encrypt(String inStr)
    {
        MessageDigest md = null;
        String outStr = null;
        try
        {
            md = MessageDigest.getInstance("MD5");
            byte digest[] = md.digest(inStr.getBytes());
            outStr = bytetoString(digest);
        }
        catch(NoSuchAlgorithmException nsae)
        {
            nsae.printStackTrace();
        }
        return outStr;
    }

    public static String bytetoString(byte digest[])
    {
        String str = "";
        String tempStr = "";
        for(int i = 1; i < digest.length; i++)
        {
            tempStr = Integer.toHexString(digest[i] & 0xff);
            if(tempStr.length() == 1)
                str = (new StringBuilder(String.valueOf(str))).append("0").append(tempStr).toString();
            else
                str = (new StringBuilder(String.valueOf(str))).append(tempStr).toString();
        }

        return str.toLowerCase();
    }
}